<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>试卷管理</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <script src="../../layui/layui.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">在线考试系统</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                <i class="layui-icon layui-icon-spread-left"></i>
            </li>

            <li class="layui-nav-item layui-hide-xs"><a href="">刷新</a></li>

        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                <a href="javascript:;">
                    <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg"
                         class="layui-nav-img">
                    student
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="information_page.html">个人中心</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item" lay-unselect>
                <a href="/index.html">退出
                </a>
            </li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">考试系统</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" data-id="1" data-title="试卷列表" data-url="index.php?&a=adminList"
                               class="site-demo-active" data-type="tabAdd">试卷列表</a></dd>
                        <dd><a href="javascript:;" lay-header-event="menuRight" lay-unselect>查看通知</a></dd>
                    </dl>
                </li>
            </ul>

        </div>
    </div>

    <div class="layui-body">
        <div class="layui-tab">
            <ul class="layui-tab-title">
                <li class="layui-this">试卷列表</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table id="testinfo" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-footer" style="text-align: center">
        <!-- 底部固定区域 -->
        ©版权 西北农林科技大学
    </div>
</div>
<script type="text/html" id="bar" lay-filter="test">
    <button type="button" class="layui-btn layui-btn-normal" lay-event="chakan">查看试卷</button>
    <button type="button" class="layui-btn layui-btn-danger" lay-event="kaishi">开始答题</button>
</script>
<script type="text/html" id="bar2" lay-filter="test">已读
</script>
<script>
    //JS
    layui.use(['element', 'layer', 'util', 'table'], function () {
        var element = layui.element
            , layer = layui.layer
            , util = layui.util
            , $ = layui.$
            , table = layui.table;
        var userID = "1004";
        $.post("/student/session",
            {
                userId: userID,
            },
            function (data) {
                console.log(data);
            });
        //头部事件
        var inf = '<div class="layui-tab">\n' +
            '            <ul class="layui-tab-title">\n' +
            '                <li class="layui-this">通知列表</li>\n' +
            '            </ul>\n' +
            '            <div class="layui-tab-content">\n' +
            '                <div class="layui-tab-item layui-show">\n' +
            '                    <table id="inform" lay-filter="test"></table>\n' +
            '                </div>\n' +
            '            </div>\n' +
            '        </div>';
        util.event('lay-header-event', {
            //左侧菜单事件
            menuLeft: function (othis) {
                layer.msg('展开左侧菜单的操作', {icon: 0});
            }
            , menuRight: function () {
                layer.open({
                    type: 1
                    , content: inf
                    , area: ['500px', '100%']
                    , offset: 'rt' //右上角
                    , anim: 5
                    , shadeClose: true
                });
                table.render({
                    elem: '#inform'
                    , height: 312
                    , url: '/student/selectmessage' //数据接口
                    , parseData: function (res) {
                        return {
                            "code": 0
                            , "msg": "暂无数据"
                            , "data": res
                        }
                    }
                    // ,page: false //开启分页
                    , cols: [[ //表头
                        {field: 'messageid', title: '通知序号'}
                        , {field: 'message', title: '通知内容'}
                        , {title: '状态', toolbar: "#bar2"}
                    ]]
                });
            }
        });

        table.render({
            elem: '#testinfo'
            , height: 312
            , url: '/student/selectbystuid' //数据接口
            , parseData: function (res) {
                return {
                    "code": 0
                    , "msg": "暂无数据"
                    , "data": res
                }
            }
            // ,page: false //开启分页
            , cols: [[ //表头
                {field: 'questionid', title: '试卷编号'}
                , {field: 'questionname', title: '科目'}
                , {field: 'questionname', title: '试卷名称'}
                , {field: 'operation', title: '操作', toolbar: "#bar"}
            ]]
        });

        table.on('tool(test)', function (obj) {
            var data = obj.data; //获得当前行数据
            var text = 0;
            // var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            // var tr = obj.tr; //获得当前行 tr 的DOM对象
            switch (obj.event) {
                case 'chakan':
                    document.cookie = 'bianhao' + '=' + data.questionid;
                    document.cookie = 'userID' + '=' + userID;
                    console.log(data.questionid + "chakan" + userID)
                    window.location.href = 'ans_page.html';
                    break;
                case 'kaishi':
                    $.ajax({
                        type: 'get',
                        url: '/student/session',
                        dataType: 'json',
                        data: {
                            questionid: data.questionid
                        },
                        async: false,
                        success: function (data) {
                            layer.open({
                                type: 2,
                                title: "正在考试",
                                closeBtn: 0,
                                area: ['1000px', '800px'],
                                content: 'exam.html',
                                btn: ['放弃考试'],
                                yes: function (index) {
                                    text = 1;
                                    layer.close(index);
                                }
                                , cancel: function (index) {
                                    text = 1;
                                    layer.close(index)
                                    return false
                                }
                            });
                        }
                    });
            }
            ;
        });

    });
</script>
</body>
</html>